<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="单据日期" prop="documentDate">
        <el-date-picker clearable
                        v-model="queryParams.documentDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择单据日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="供应商id" prop="supId">
        <el-input
          v-model="queryParams.supId"
          placeholder="请输入供应商id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="核销金额" prop="reconciliationAmount">
        <el-input
          v-model="queryParams.reconciliationAmount"
          placeholder="请输入核销金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="生效时间" prop="effectiveTime">
        <el-date-picker clearable
                        v-model="queryParams.effectiveTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择生效时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="审批人" prop="approver">
        <el-input
          v-model="queryParams.approver"
          placeholder="请输入审批人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="制单人" prop="createBy">
        <el-input
          v-model="queryParams.createBy"
          placeholder="请输入制单人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="修改人" prop="modifyBy">
        <el-input
          v-model="queryParams.modifyBy"
          placeholder="请输入修改人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="修改时间" prop="modifyTime">
        <el-date-picker clearable
                        v-model="queryParams.modifyTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择修改时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="核批意见" prop="approvalRemark">
        <el-input
          v-model="queryParams.approvalRemark"
          placeholder="请输入核批意见"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单据编号" prop="documentCode">
        <el-input
          v-model="queryParams.documentCode"
          placeholder="请输入单据编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['finance:payrReconciliation:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['finance:payrReconciliation:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['finance:payrReconciliation:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['finance:payrReconciliation:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="payrReconciliationList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <!--      <el-table-column label="单据id" align="center" prop="id" />-->
      <el-table-column label="序号" width="70" align="center" fixed="left">
        <template slot-scope="scope">
          {{
            scope.$index + 1 + (queryParams.pageNum - 1) * queryParams.pageSize
          }}
        </template>
      </el-table-column>
      <el-table-column label="单据编号" width="200" align="center" prop="documentCode">
        <template slot-scope="scope">
          <el-button type="text" @click="showView(scope.row)">{{
              scope.row.documentCode
            }}
          </el-button>
        </template>
      </el-table-column>
      <el-table-column label="单据日期" align="center" prop="documentDate" width="180">
      </el-table-column>
      <!--      <el-table-column label="供应商id" align="center" prop="supId"/>-->
      <el-table-column label="供应商名称" width="200" align="center" prop="supName"/>
      <el-table-column label="核销金额" align="center" prop="reconciliationAmount"/>
      <el-table-column label="单据阶段" align="center" prop="documentStage">
        <template slot-scope="scope">
          {{ scope.row.documentStage == 0 ? "编制中" : "执行完" }}
        </template>
      </el-table-column>
      <el-table-column label="核批结果" align="center" prop="approvalResult">
        <template slot-scope="scope">
          {{ scope.row.approvalResult == 0 ? "待审核" : scope.row.approvalResult == 1 ? "审核通过" : "驳回" }}
        </template>
      </el-table-column>
      <el-table-column label="已生效" align="center" prop="isEffect">
        <template slot-scope="scope">
          {{ scope.row.isEffect == 0 ? "否" : "是" }}
        </template>
      </el-table-column>
      <el-table-column label="已关闭" align="center" prop="isClose">
        <template slot-scope="scope">
          {{ scope.row.isClose == 0 ? "否" : "是" }}
        </template>
      </el-table-column>
      <el-table-column label="已作废" align="center" prop="isCancel">
        <template slot-scope="scope">
          {{ scope.row.isCancel == 0 ? "否" : "是" }}
        </template>
      </el-table-column>
      <el-table-column label="生效时间" align="center" prop="effectiveTime" width="180">
      </el-table-column>
      <el-table-column label="审批人" align="center" prop="approver"/>
      <el-table-column label="制单人" align="center" prop="createBy"/>
      <el-table-column label="制单时间" width="200" align="center" prop="createTime"/>
      <el-table-column label="修改人" align="center" prop="modifyBy"/>
      <el-table-column label="修改时间" align="center" prop="modifyTime" width="180">
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark"/>
      <el-table-column label="核批意见" align="center" prop="approvalRemark"/>
      <el-table-column label="操作" width="200" fixed="right" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            :disabled="scope.row.isEffect==1||scope.row.isCancel==1||scope.row.isClose==1||scope.row.approvalResult==1||scope.row.documentStage==1"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleCheck(scope.row)"
            v-hasPermi="['finance:payrReconciliation:edit']"
          >审核
          </el-button>
          <el-button
            :disabled="scope.row.isEffect==1||scope.row.isCancel==1||scope.row.isClose==1||scope.row.approvalResult==1||scope.row.documentStage==1"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['finance:payrReconciliation:edit']"
          >修改
          </el-button>
          <el-button
            :disabled="scope.row.isEffect==1||scope.row.isCancel==1||scope.row.isClose==1||scope.row.approvalResult==1||scope.row.documentStage==1"
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['finance:payrReconciliation:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改应付核销单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" inline label-width="80px">
        <el-form-item label="单据日期" prop="documentDate">
          <el-date-picker clearable
                          :disabled="isView"
                          v-model="form.documentDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择单据日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="供应商" prop="supId">
          <el-select v-model="form.supId" placeholder="请选择"
                     :disabled="this.reconciliationPaymentData.length>0||this.reconciliationPayableData.length>0"
                     @change="supSelectChanged"
          >
            <el-option
              v-for="item in supplierList"
              :key="item.id"
              :label="item.supName"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="单据编号" prop="documentCode">
          <el-input v-model="form.documentCode" disabled placeholder="请输入单据编号"/>
        </el-form-item>
        <el-form-item label="核销金额" prop="reconciliationAmount">
          <el-input v-model="form.reconciliationAmount" disabled placeholder="请输入核销金额"/>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" :disabled="isView" placeholder="请输入备注"/>
        </el-form-item>
      </el-form>

      <el-row :gutter="20">
        <!-- 左侧 -->
        <el-col :span="12" v-if="!isView">
          <div>
            <!-- 应付单 -->
            <h3>应付单</h3>
            <el-table :data="payableData" style="width: 100%" @selection-change="handleSelectionChange2">
              <el-table-column type="selection" width="55"></el-table-column>
              <el-table-column prop="code" label="单据号" width="150"></el-table-column>
              <el-table-column prop="sourceCode" label="源单号" width="150"></el-table-column>
              <el-table-column prop="noVerAmount" label="未核销金额" width="150"></el-table-column>
              <el-table-column prop="remark" label="备注" width="150"></el-table-column>
            </el-table>
            <el-button size="small" type="primary" @click="addMustPay">添加</el-button>
          </div>

          <div style="margin-top: 20px;">
            <!-- 付款单 -->
            <h3>付款单</h3>
            <el-table :data="paymentData" style="width: 100%" @selection-change="handleSelectionChange3">
              <el-table-column type="selection" width="55"></el-table-column>
              <el-table-column prop="code" label="单据号" width="150"></el-table-column>
              <el-table-column prop="codeTypeName" label="付款类型" width="150"></el-table-column>
              <el-table-column prop="noVerAmount" label="未核销金额" width="150"></el-table-column>
              <el-table-column prop="remark" label="备注" width="150"></el-table-column>
            </el-table>
            <el-button size="small" type="primary" @click="addPay">添加</el-button>
          </div>
        </el-col>

        <!-- 右侧 -->
        <el-col :span="12">
          <div>
            <!-- 核销明细-应付 -->
            <h3>核销明细-应付</h3>
            <el-table :data="reconciliationPayableData" style="width: 100%" @selection-change="handleSelectionChange4">
              <el-table-column type="selection" width="55"></el-table-column>
              <el-table-column prop="sourceDocumentNo" label="源单号" width="150"></el-table-column>
              <el-table-column prop="typeName" label="源单类型" width="150"></el-table-column>
              <el-table-column prop="noVerAmount" label="未核销金额" width="150"></el-table-column>
              <el-table-column prop="reconciliationAmount" label="核销金额" width="150">
                <template slot-scope="scope">
                  <el-input
                    :disabled="isView"
                    v-model="scope.row.reconciliationAmount"
                    @change="changeAmount(scope.row)"
                    placeholder="请输入金额"
                    size="small"
                  ></el-input>
                </template>
              </el-table-column>
            </el-table>
            <el-button v-if="!isView" size="small" type="primary" @click="delMustPay">移除</el-button>
            <p>合计: <span>{{ mustPayAll }}</span></p>
          </div>

          <div style="margin-top: 20px;">
            <!-- 核销明细-付款 -->
            <h3>核销明细-付款</h3>
            <el-table :data="reconciliationPaymentData" style="width: 100%" @selection-change="handleSelectionChange5">
              <el-table-column type="selection" width="55"></el-table-column>
              <el-table-column prop="sourceDocumentNo" label="源单号" width="150"></el-table-column>
              <el-table-column prop="typeName" label="源单类型" width="150"></el-table-column>
              <el-table-column prop="noVerAmount" label="未核销金额" width="150"></el-table-column>
              <el-table-column prop="reconciliationAmount" label="核销金额" width="150">
                <template slot-scope="scope">
                  <el-input
                    :disabled="isView"
                    v-model="scope.row.reconciliationAmount"
                    @change="changeAmount(scope.row)"
                    placeholder="请输入金额"
                    size="small"
                  ></el-input>
                </template>
              </el-table-column>
            </el-table>
            <el-button v-if="!isView" size="small" type="primary" @click="delPay">移除</el-button>
            <p>合计: <span>{{ payAll }}</span></p>
          </div>
          <el-alert
            v-if="mustPayAll !== payAll"
            title="上下核销金额合计不相等！"
            type="warning"
            show-icon>
          </el-alert>
        </el-col>

      </el-row>
      <div slot="footer" class="dialog-footer">
        <el-button :disabled="isView" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listPayrReconciliation,
  getPayrReconciliation,
  delPayrReconciliation,
  addPayrReconciliation,
  updatePayrReconciliation
} from "@/api/finance/payrReconciliation";
import {listSupplies} from "@/api/basedata/supplies";
import request from "@/utils/request";

export default {
  name: "PayrReconciliation",
  data() {
    return {
      mustPayAll: 0,
      payAll: 0,
      payableData: [],
      paymentData: [],
      reconciliationPayableData: [],
      reconciliationPaymentData: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 应付核销单表格数据
      payrReconciliationList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        documentDate: null,
        supId: null,
        reconciliationAmount: null,
        documentStage: null,
        approvalResult: null,
        isEffect: null,
        isClose: null,
        isCancel: null,
        effectiveTime: null,
        approver: null,
        createBy: null,
        modifyBy: null,
        modifyTime: null,
        approvalRemark: null,
        documentCode: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        documentDate: [
          {required: true, message: "单据日期不能为空", trigger: "blur"}
        ],
        supId: [
          {required: true, message: "供应商id不能为空", trigger: "blur"}
        ],
        reconciliationAmount: [
          {required: true, message: "核销金额不能为空", trigger: "blur"}
        ],
        documentStage: [
          {required: true, message: "单据阶段不能为空", trigger: "blur"}
        ],
        approvalResult: [
          {required: true, message: "核批结果(1.待审核 1.审核通过 2.驳回)不能为空", trigger: "blur"}
        ],
        isEffect: [
          {required: true, message: "已生效 (1: 是, 0: 否)不能为空", trigger: "blur"}
        ],
        isClose: [
          {required: true, message: "已关闭 (1: 是, 0: 否)不能为空", trigger: "blur"}
        ],
        isCancel: [
          {required: true, message: "已作废 (1: 是, 0: 否)不能为空", trigger: "blur"}
        ],
        createBy: [
          {required: true, message: "制单人不能为空", trigger: "blur"}
        ],
        createTime: [
          {required: true, message: "制单时间不能为空", trigger: "blur"}
        ],
        documentCode: [
          {required: true, message: "单据编号不能为空", trigger: "blur"}
        ]
      },
      supplierList: [],
      ids2: [],
      ids3: [],
      ids4: [],
      ids5: [],
      isView: false,

    };
  },
  created() {
    this.getList();
    this.getSupplierList();
  },
  methods: {
    //审核
    handleCheck(row) {
      request({
        url: "/finance/payrReconciliation/checkRecon",
        method: "post",
        data: row
      }).then(res => {
        this.$modal.msgSuccess("审核成功");
        this.getList();
      }).catch(e => {
        this.$modal.msgSuccess(e.response.data);
      })
    },
    //查看详情
    showView(row) {
      this.title = "查看应付核销单";
      request({
        url: "/finance/payrReconciliation/" + row.id,
        methods: "get",
      }).then(res => {
        this.form = res.data;
        const detailList = this.form.payReconciliationDetailList;
        detailList.forEach(item => {
          if (item.sourceDocumentType == 1) {
            item.noVerAmount = item.mustPayNoVerAmount;
            this.reconciliationPayableData.push(item);
          } else {
            item.noVerAmount = item.payNoVerAmount;
            this.reconciliationPaymentData.push(item);
          }
        })
        this.calData();
        this.isView = true;
        this.open = true;
      })
    },
    //改变核销金额
    changeAmount(row) {
      if (isNaN(row.reconciliationAmount) || row.reconciliationAmount <= 0) {
        this.$notify({
          title: '警告',
          message: '请输入正整数',
          type: 'warning',
        });
        row.reconciliationAmount = row.noVerAmount; // 恢复
        return;
      }
      if (row.reconciliationAmount > row.noVerAmount) {
        this.$notify({
          title: '警告',
          message: `输入的数量不能大于` + row.noVerAmount,
          type: 'warning',
        });
        row.reconciliationAmount = row.noVerAmount; // 恢复
        return;
      }
      this.calData();
    },
    calData() {
      let mustPayAll = 0;
      this.reconciliationPayableData.forEach(item => {
        mustPayAll = parseFloat(mustPayAll) + parseFloat(item.reconciliationAmount);
      })
      this.mustPayAll = mustPayAll;
      let payAll = 0;
      this.reconciliationPaymentData.forEach(item => {
        payAll = parseFloat(payAll) + parseFloat(item.reconciliationAmount);
      })
      this.payAll = payAll;
      if (this.mustPayAll == this.payAll) {
        this.form.reconciliationAmount = this.payAll;
      }
    },
    //选择供应商后将供应商的和核销应付单和可核销付款单查询出来
    supSelectChanged() {
      request({
        url: "/finance/buyMustPay/getReconList",
        params: {
          supId: this.form.supId
        },
        methods: "get"
      }).then(res => {
        this.payableData = res.rows;
        //将未核销金额计算一下
        this.payableData.forEach(item => {
          item.noVerAmount = item.totalAmount - item.verifiedAmount;
        })
      });
      request({
        url: "/finance/payment/getReconList",
        params: {
          supId: this.form.supId
        },
        methods: "get"
      }).then(res => {
        this.paymentData = res.rows;
        this.paymentData.forEach(item => {
          item.noVerAmount = item.totalAmount - item.verifiedAmount;
        })
      });
    },
    //选择左侧改变右侧
    addMustPay() {
      this.reconciliationPayableData =
        this.payableData.filter(item =>
          this.ids2.includes(item.id))
          .map(item => ({
            id: item.id,
            sourceDocumentNo: item.code,
            sourceDocumentType: 1,
            typeName: "应付单",
            reconciliationAmount: item.noVerAmount,
            noVerAmount: item.noVerAmount
          }));
      this.calData();
    },
    addPay() {
      this.reconciliationPaymentData =
        this.paymentData.filter(item =>
          this.ids3.includes(item.id)).map(item => ({
          id: item.id,
          sourceDocumentNo: item.code,
          typeName: "付款单",
          sourceDocumentType: 2,
          reconciliationAmount: item.noVerAmount,
          noVerAmount: item.noVerAmount
        }));
      this.calData();
    },
    //移除右侧
    delMustPay() {
      this.reconciliationPayableData = this.reconciliationPayableData
        .filter(item => !this.ids4.includes(item.id));
      this.calData();
    },
    delPay() {
      this.reconciliationPaymentData = this.reconciliationPaymentData
        .filter(item => !this.ids5.includes(item.id));
      this.calData();
    },
    //获取供应商列表
    getSupplierList() {
      listSupplies().then(res => {
        this.supplierList = res.rows
      })
    },
    /*  * 查询应付核销单列表 */
    getList() {
      this.loading = true;
      listPayrReconciliation(this.queryParams).then(response => {
        this.payrReconciliationList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        documentDate: null,
        supId: null,
        reconciliationAmount: null,
        documentStage: null,
        approvalResult: null,
        isEffect: null,
        isClose: null,
        isCancel: null,
        effectiveTime: null,
        approver: null,
        createBy: null,
        createTime: null,
        modifyBy: null,
        modifyTime: null,
        remark: null,
        approvalRemark: null,
        documentCode: null
      };
      this.isView = false;
      this.mustPayAll = 0;
      this.payAll = 0;
      this.payableData = [];
      this.paymentData = [];
      this.reconciliationPayableData = [];
      this.reconciliationPaymentData = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    handleSelectionChange2(selection) {
      this.ids2 = selection.map(item => item.id)
    },
    handleSelectionChange3(selection) {
      this.ids3 = selection.map(item => item.id)
    },
    handleSelectionChange4(selection) {
      this.ids4 = selection.map(item => item.id)
    },
    handleSelectionChange5(selection) {
      this.ids5 = selection.map(item => item.id)
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.title = "添加应付核销单";
      this.getSupplierList();
      this.form.documentCode = "YFHX-" + Date.now();
      const today = new Date();
      const year = today.getFullYear();
      const month = String(today.getMonth() + 1).padStart(2, '0'); // 月份是从0开始的
      const day = String(today.getDate()).padStart(2, '0');
      this.form.documentDate = `${year}-${month}-${day}`;
      this.open = true;
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.title = "修改应付核销单";
      const id = row.id || this.ids;
      getPayrReconciliation(id).then(res => {
        this.form = res.data;
        this.supSelectChanged();
        const detailList = this.form.payReconciliationDetailList;
        detailList.forEach(item => {
          if (item.sourceDocumentType == 1) {
            item.noVerAmount = item.mustPayNoVerAmount;
            this.reconciliationPayableData.push(item);
          } else {
            item.noVerAmount = item.payNoVerAmount;
            this.reconciliationPaymentData.push(item);
          }
        })
        this.calData();
        this.open = true;
      });
    },
    //提交数据校验
    checkForm() {
      if (this.form.documentDate == null) {
        this.$notify({
          title: "警告",
          type: "warning",
          message: "请填写单据日期"
        })
        return false;
      }
      if (this.form.supId == null) {
        this.$notify({
          title: "警告",
          type: "warning",
          message: "请选择供应商"
        })
        return false
      }
      if (this.form.documentCode == null || this.form.documentCode == '') {
        this.$notify({
          title: "警告",
          type: "warning",
          message: "请填写单据编号"
        })
        return false;
      }
      if (this.form.reconciliationAmount == null || this.form.reconciliationAmount <= 0) {
        this.$notify({
          title: "警告",
          type: "warning",
          message: "核销金额必须大于0"
        })
        return false;
      }
      if (this.mustPayAll != this.payAll) {
        this.$notify({
          title: "警告",
          type: "warning",
          message: "核销金额不相等"
        })
        return false;
      }
      return true;
    },
    /** 提交按钮 */
    submitForm() {
      if (this.checkForm()) {
        if (this.form.id != null) {
          this.form.modifyBy = this.$store.getters.name;
          this.modifyTime = Date.now();
          this.form.payReconciliationDetailList = [];
          this.reconciliationPayableData.forEach(item => {
            item.reconciliationCode = this.form.documentCode;
            this.form.payReconciliationDetailList.push(item);
          })
          this.reconciliationPaymentData.forEach(item => {
            item.reconciliationCode = this.form.documentCode;
            this.form.payReconciliationDetailList.push(item);
          })
          console.log("form", this.form);
          updatePayrReconciliation(this.form).then(response => {
            this.$modal.msgSuccess("修改成功");
            this.open = false;
            this.getList();
          });
        } else {
          this.form.createBy = this.$store.getters.name;
          this.createTime = Date.now();
          this.form.payReconciliationDetailList = [];
          this.reconciliationPayableData.forEach(item => {
            item.reconciliationCode = this.form.documentCode;
            this.form.payReconciliationDetailList.push(item);
          })
          this.reconciliationPaymentData.forEach(item => {
            item.reconciliationCode = this.form.documentCode;
            this.form.payReconciliationDetailList.push(item);
          })
          addPayrReconciliation(this.form).then(response => {
            this.$modal.msgSuccess("新增成功");
            this.open = false;
            this.getList();
          });
        }
      }

    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除应付核销单编号为"' + ids + '"的数据项？').then(function () {
        return delPayrReconciliation(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('finance/payrReconciliation/export', {
        ...this.queryParams
      }, `payrReconciliation_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style scoped>
h3 {
  margin: 10px 0;
}
</style>
